<!DOCTYPE html><html><head><title>README</title><link href="http://www.jboss.org/jdf/stylesheets/documentation.css" rel="stylesheet"></link><link href="http://www.jboss.org/jdf/stylesheets/pygments.css" rel="stylesheet"></link></head><body>
<h1><a id="forgefromscratch-example-showing-how-forge-can-generate-an-application-from-scratch" class="anchor" href="#forgefromscratch-example-showing-how-forge-can-generate-an-application-from-scratch"><span class="anchor-icon"></span></a>forge-from-scratch: Example Showing How Forge Can Generate an Application From Scratch</h1>

<p>Author: Lincoln Baxter<br/>
Level: Intermediate<br/>
Technologies: Forge<br/>
Summary: Demonstrates how to generate a fully Java EE compliant project using nothing but JBoss Forge<br/>
Target Product: EAP<br/>
Product Versions: EAP 6.1, EAP 6.2, Forge 1.0.0.Final<br/>
Source: <a href="https://github.com/jboss-developer/jboss-eap-quickstarts/">https://github.com/jboss-developer/jboss-eap-quickstarts/</a>  </p>

<h2><a id="what-is-it" class="anchor" href="#what-is-it"><span class="anchor-icon"></span></a>What is it?</h2>

<p>This quickstart demonstrates how to create a fully <strong>Java EE compliant</strong> project using nothing but  <strong>JBoss Forge</strong>. </p>

<p>Once generated, the sample project will be a standard Maven 3, Java Web project with <strong>JPA 2.0, EJB 3.1, CDI 1.0, JSF 2.0</strong> with complete <strong>JAX-RS</strong> endpoints for all data Entities. It will also provide views to Create, Read, Update, and Delete records.</p>

<p>But that is not all! You can use Forge on your new or existing projects to continue to enhance any application.</p>

<h2><a id="system-requirements" class="anchor" href="#system-requirements"><span class="anchor-icon"></span></a>System requirements</h2>

<p>The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later.</p>

<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or later, and a JBoss Developer Studio 5 or JBoss Forge version 1.0.0.Final (or later).</p>

<h3><a id="jboss-developer-studio-5" class="anchor" href="#jboss-developer-studio-5"><span class="anchor-icon"></span></a>JBoss Developer Studio 5</h3>

<p>Forge is available in JBoss Developer Studio 5. </p>

<p>To show the Forge Console, navigate to <em>Window -> Show View -> Other</em>, locate <em>Forge Console</em> and click <em>OK</em>. Then click the <em>Start</em> button in top right corner of the view.</p>

<h3><a id="jboss-enterprise-application-platform" class="anchor" href="#jboss-enterprise-application-platform"><span class="anchor-icon"></span></a>JBoss Enterprise Application Platform</h3>

<p>If you do not plan to use JBoss Developer Studio, you should install JBoss Forge version 1.0.0.Final or later. Follow the instructions at <a href="https://docs.jboss.org/author/display/FORGE/Installation">Installing Forge</a>.</p>

<p>Open a command line and navigate to the root directory of this quickstart. </p>

<p>Launch Forge by typing the following command:</p>
<div class="highlight"><pre>    <span class="n">forge</span>
</pre></div>
<h2><a id="generate-build-and-deploy-the-application" class="anchor" href="#generate-build-and-deploy-the-application"><span class="anchor-icon"></span></a>Generate, Build, and Deploy the Application</h2>

<p>In the Forge console, make sure you are in the directory where this README.html file is located:</p>
<div class="highlight"><pre>   <span class="n">forge</span><span class="o">&gt;</span> <span class="n">cd</span> <span class="n">QUICKSTART_HOME</span><span class="o">/</span><span class="n">forge</span><span class="o">-</span><span class="n">from</span><span class="o">-</span><span class="n">scratch</span><span class="o">/</span>
</pre></div>
<p>Notice that there is a file in this directory named <code>generate.fsh</code>. Run this file from Forge using the <code>run</code> command:</p>
<div class="highlight"><pre>    <span class="n">forge</span><span class="o">&gt;</span> <span class="n">run</span> <span class="n">generate</span><span class="p">.</span><span class="n">fsh</span>
</pre></div>
<p>This command will prompt you to enter a <code>project-name</code>, for example: &lsquo;example&rsquo;</p>

<p>After this, you see a lot of console messages with a <code>[INFO] BUILD SUCCESS</code> towards the end.</p>

<h2><a id="what-did-this-create" class="anchor" href="#what-did-this-create"><span class="anchor-icon"></span></a>What Did This Create?</h2>

<p>This quickstart has created a native Java EE 6 application. </p>

<p>After this command completes, look in your <code>QUICKSTART_HOME/forge-from-scratch/</code> folder. You will see a folder with the same name as the <code>project-name</code> you entered in the prompt above. Browse through this project to see the code that was generated as a result of this command. </p>

<p>For a full description of what was generated by running this script and details on the structure of the application, visit the <a href="https://docs.jboss.org/author/display/FORGE/UI+Scaffolding">Forge UI Scaffolding Guide</a></p>

<h2><a id="configure-maven-" class="anchor" href="#configure-maven-"><span class="anchor-icon"></span></a>Configure Maven </h2>

<p>If you have not yet done so, you must <a href="../README.html#configure-maven">Configure Maven</a> before testing the quickstarts. </p>

<h2><a id="start-the-jboss-server" class="anchor" href="#start-the-jboss-server"><span class="anchor-icon"></span></a>Start the JBoss Server</h2>

<ol>
<li>Open a command line and navigate to the root of the JBoss server directory.</li>
<li><p>The following shows the command line to start the server:</p>
<div class="highlight"><pre><span class="n">For</span> <span class="n">Linux</span><span class="o">:</span>   <span class="n">JBOSS_HOME</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">standalone</span><span class="p">.</span><span class="n">sh</span>
<span class="n">For</span> <span class="n">Windows</span><span class="o">:</span> <span class="n">JBOSS_HOME</span><span class="err">\</span><span class="n">bin</span><span class="err">\</span><span class="n">standalone</span><span class="p">.</span><span class="n">bat</span>
</pre></div></li>
</ol>

<h2><a id="deploy-and-test-the-newly-generated-application" class="anchor" href="#deploy-and-test-the-newly-generated-application"><span class="anchor-icon"></span></a>Deploy and test the newly generated application</h2>

<p>Make sure you have started the JBoss server. See the instructions in the previous section.</p>

<ol>
<li><p>Build the application:</p>
<div class="highlight"><pre><span class="n">forge</span><span class="o">&gt;</span> <span class="n">build</span>
</pre></div></li>
<li><p>Use the <code>jboss-as-7</code> Forge plugin to deploy the application. Install it with the following command:</p>
<div class="highlight"><pre><span class="n">forge</span><span class="o">&gt;</span> <span class="n">forge</span> <span class="n">install</span><span class="o">-</span><span class="n">plugin</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">-</span><span class="mi">7</span>
</pre></div></li>
<li><p>Configure the server information:</p>
<div class="highlight"><pre><span class="n">forge</span><span class="o">&gt;</span> <span class="n">as7</span> <span class="n">setup</span>
</pre></div>
<p>You will be prompted with three questions. Type &lsquo;N&rsquo; for the first two questions to keep the default settings. Enter the path to your server install for the third question.</p></li>
<li><p>Now deploy the application:</p>
<div class="highlight"><pre><span class="n">forge</span><span class="o">&gt;</span> <span class="n">as7</span> <span class="n">deploy</span>
</pre></div>
<p>This will deploy <code>target/YOUR_PROJECT_NAME.war</code>.</p></li>
<li><p>The application will be running at the following URL: <a href="http://localhost:8080/YOUR_PROJECT_NAME/">http://localhost:8080/YOUR_PROJECT_NAME/</a>.</p>

<p>Be sure to replace <code>YOUR_PROJECT_NAME</code> with the name of the project you chose when running the script.</p></li>
<li><p>When you are ready to undeploy from JBoss AS, run this command:</p>
<div class="highlight"><pre><span class="n">forge</span><span class="o">&gt;</span> <span class="n">as7</span> <span class="n">undeploy</span>
</pre></div></li>
</ol>

<h2><a id="next-steps" class="anchor" href="#next-steps"><span class="anchor-icon"></span></a>Next Steps</h2>

<p>Open <code>generate.fsh</code> and take a look inside! There is not much magic happening here. All of the commands used to generate this project are clearly listed just as if they were typed by your own hands.</p>

<p>Play around with creating more entities, relationships, UI, and generating JAX-RS endpoints,all with just a few simple commands.</p>

<h2><a id="explore-plugins-" class="anchor" href="#explore-plugins-"><span class="anchor-icon"></span></a>Explore plugins! </h2>

<p>Forge has a rich plugin ecosystem. Want to deploy your application to the Cloud? Use the Forge Openshift plugin: <a href="http://github.com/forge/plugin-openshift/">http://github.com/forge/plugin-openshift/</a></p>

<p>To see a full list of avaialable plugins, make sure that you have an active internet connection and type:</p>
<div class="highlight"><pre>    <span class="n">forge</span><span class="o">&gt;</span> <span class="n">forge</span> <span class="n">find</span><span class="o">-</span><span class="n">plugin</span> <span class="o">*</span>
</pre></div>
<h2><a id="run-the-quickstart-in-jboss-developer-studio-or-eclipse" class="anchor" href="#run-the-quickstart-in-jboss-developer-studio-or-eclipse"><span class="anchor-icon"></span></a>Run the Quickstart in JBoss Developer Studio or Eclipse</h2>

<p>You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see <a href="../README.html#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts">Use JBoss Developer Studio or Eclipse to Run the Quickstarts</a> </p>

<h2><a id="debug-the-application" class="anchor" href="#debug-the-application"><span class="anchor-icon"></span></a>Debug the Application</h2>

<p>If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.</p>
<div class="highlight"><pre>    <span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">sources</span>
    <span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">resolve</span> <span class="o">-</span><span class="n">Dclassifier</span><span class="o">=</span><span class="n">javadoc</span>
</pre></div></body></html>
